/*
 * Copyright 2010 EES GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * 	http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.eesgmbh.gimv.samples.googlechartapi.client.infobox;

import org.eesgmbh.gimv.samples.googlechartapi.client.infobox.InfoBoxPresenter.View;
import org.eesgmbh.gimv.shared.util.Point;

import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Label;

/**
 * InfoBox View to display the current mouse position and the
 * link to the chart image.
 *
 * @author Sascha Hagedorn - EES GmbH - s.hagedorn@ees-gmbh.de
 *
 */
public class InfoBoxViewImpl implements View {

	private Anchor url;
	private Label mousePositionLabel;

	public InfoBoxViewImpl(Anchor url, Label mousePositionLabel) {
		this.url = url;
		this.mousePositionLabel = mousePositionLabel;
		setMousePositionLabel(new Point(0.0, 0.0));
	}

	public void setUrl(String urlString) {
		url.setHref(urlString);
	}

	public void setMousePositionLabel(Point position) {
		mousePositionLabel.setText(formatCoordinate(position.getX()) + ", " + formatCoordinate(position.getY()));
	}

	private String formatCoordinate(Double value) {
		if (value < 10) {
			return "00" + value.intValue();
		} else if (value < 100) {
			return "0" + value.intValue();
		} else {
			return Integer.toString(value.intValue());
		}
	}
}
